// 引入操作t_admin表的db模块
let db = require("../db/banner.js");

let util = require("../../util");

/**
 * @param {Object} data 请求参数
 */
exports.queryList = async function (data, callback) {
    console.log("banner.queryList.data = ", data);
    util.setupPage(data, "update_time desc");
    try {
        let result = await db.queryList(data);
        let returnData = {
            status: 1,
            msg: "查询成功",
            result_data: result
        }
        let count = await db.queryCount(data);
        returnData.count = count;
        callback(returnData);
    } catch {
        callback({
            status: -1,
            msg: "查询失败",
        });
    }
}

/**
 * 增加banner图数据
 * @param {Object} data 请求参数
 * @param {Function} callback 回调函数 
 */
 exports.insert = async function (data, callback) {
    console.log("banner.insert.data = ", data);
    try {
        let result = await db.insert(data)
        if (result.affectedRows != 1) {
            callback({
                status: -1,
                msg: "增加失败",
            })
        } else {
            callback({
                status: 1,
                msg: "增加成功"
            })
        }
    } catch {
        callback({
            status: -1,
            msg: "增加失败，电话号码重复",
        });
    }
}